from django.db import models


# Create your models here.

# 会员信息模型
class Users(models.Model):
    # 主要信息: id, 手机号, 密码, 头像
    phone = models.CharField(max_length=11)
    password = models.CharField(max_length=80)  # 密码加密后是78位
    face = models.CharField(max_length=100, default="/static/myadmin/assets/img/user07.png")
    # 次要信息: 昵称, 居住地址, 性别, 身份类型
    nickname = models.CharField(max_length=20, null=True)
    homeaddress = models.CharField(max_length=100, null=True)
    sex = models.CharField(max_length=1, null=True)
    # a 狼人 b 预言家 c 平民
    usertype = models.CharField(max_length=1, null=True)
    registerdate = models.DateTimeField(auto_now_add=True)


# 图书分类模型
class Booktype(models.Model):
    name = models.CharField(max_length=20)
    pid = models.IntegerField()
    path = models.CharField(max_length=50)


'''
id    name    pid    path
1     服装     0      0,
2     男装     1      0,1,
3     衬衫     2      0,1,2,
'''

# 图书商品模型
'''
    书名,推荐语  
    作者,出版社,出版时间,  
    价格,书号ISBN  
    所属分类ID  
    封面图  
    产品特色,编辑推荐,内容简介,作者简介,目录,媒体评论,试读章节  
'''


class Books(models.Model):
    typeid = models.ManyToManyField(to="Booktype")
    title = models.CharField(max_length=50)
    tuijian = models.CharField(max_length=255)
    author = models.CharField(max_length=50)
    publisher = models.CharField(max_length=100)
    pub_date = models.DateField()
    price = models.FloatField()
    num = models.IntegerField()
    ISBN = models.CharField(max_length=30)
    context = models.TextField()


# 图书封面图集
class BookImgs(models.Model):
    bookid = models.ForeignKey('Books', on_delete=models.CASCADE, )
    img_url = models.ImageField(upload_to='static/uploads/')


# 购物车模型
class Cart(models.Model):
    # id 用户id 商品id 数量 是否选中select
    uid = models.ForeignKey('Users', on_delete=models.CASCADE, )
    bid = models.ForeignKey('Books', on_delete=models.CASCADE, )
    num = models.IntegerField()
    # 是否选中 0未选中 1选中
    select = models.IntegerField(default=0)


# 订单模型
class Order(models.Model):
    '''
    订单号(时间戳+随机数+订单号),uid,收货信息,总价,状态,订单创建时间,订单支付时间
    10001自增                 1024         99.99 0
    '''
    uid = models.ForeignKey('Users', on_delete=models.CASCADE,)
    name = models.CharField(max_length=10)
    phone = models.CharField(max_length=11)
    address = models.CharField(max_length=100)
    totalprice = models.FloatField()
    # 0未支付 1已支付 2待收货 3已取消
    status = models.IntegerField(default=0)
    ordertime = models.DateTimeField(auto_now_add=True)
    paytime = models.DateTimeField(null=True)


# 订单详情
class OrderDetail(models.Model):
    '''
    id,订单号,商品id,商品数量,商品价格
        10001   10      2       10
        10001   8       1       10
    '''
    orderid = models.ForeignKey('Order', on_delete=models.CASCADE,)
    bid = models.ForeignKey('Books', on_delete=models.CASCADE,)
    num = models.IntegerField()
    price = models.FloatField()




